import torch
from ultralytics import YOLO

# 加载预训练的 YOLOv5 模型
# model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True)
# model.eval()

# 加载 YOLO8 模型
global model
model = YOLO('yolov8s.pt').to('cuda' if torch.cuda.is_available() else 'cpu')


def detect_objects(image):
    results = model(image)
    return results.pandas().xyxy[0].to_json(orient="records")
